package com.yycx.module.bus.provider.handler.supplierbond;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.constants.CommonConstants;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.security.OpenHelper;
import com.yycx.module.admin.client.entity.BaseUser;
import com.yycx.module.bus.client.entity.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 待垫付订单列表
 *
 * @author zyf
 */
@Component("supplierBondNoPageListHandler")
public class SupplierBondNoPageListHandler implements PageInterceptor<BusOrderDetails>{


    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        cq.clear();
        String beginDate = params.get("beginDate");
        String endDate = params.get("endDate");
        Long companyId= OpenHelper.getCompanyId();
        cq.select("sum(supplierBond) supplierBond","saleNum");
        cq.addSelect(BusOrder.class, "orderId","orderNo","sendDate","supplierBondType","customBondType","takeAmount","takeDate","supplierId","createTime");
        cq.addSelect(BusSupplier.class,"supplierName");
        cq.addSelect(BusDrugs.class, "drugsName", "drugsSpec");
        cq.addSelect(BusCustom.class,"customName");
        cq.addSelect(BusDept.class,"deptName");
        cq.addSelect(BaseUser.class, "nickName");
        cq.addSelect(BusSaleman.class,"saleManName");
        cq.eq(true,"bod.companyId",companyId);
        cq.eq(true,"bod.saleType",CommonConstants.INT_1);
        cq.eq(true,"bod.supplierBondState", CommonConstants.INT_0);
        cq.like(BusOrder.class,"orderNo");
        cq.eq("ord.orderState",CommonConstants.INT_2);
        if (FlymeUtils.isNotEmpty(beginDate)) {
            cq.ge(BusOrder.class, "sendDate", beginDate);
        }
        if (FlymeUtils.isNotEmpty(endDate)) {
            cq.le(BusOrder.class, "sendDate", endDate);
        }
        cq.eq(BusSupplier.class,"supplierId");
        cq.createJoin(BusDept.class);
        cq.createJoin(BaseUser.class).setMainAlias("ord");
        cq.createJoin(BusSaleman.class).setMainAlias("ord");
        cq.groupBy("bod.orderId");
    }


}
